package hello;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.Transaction;

import persistence.HibernateUtil;
import auction.model.Image;
import auction.model.ItemValueType;

public class HelloWorldValueType
{
	
	
	public static void main(String[] args)throws Exception
	{
		
		Session s=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=s.beginTransaction();
		
		
		
		ItemValueType itemValueType=new ItemValueType();
		
		/*
		Set<Image> imgc=new HashSet<Image>();
		imgc.add(new Image("Foo","Foo.jpg",123,123));
		imgc.add(new Image("Bar","Foo.jpg",123,123));
		itemValueType.setImageComponentSet(imgc);
		
		
		Set<String> imgs=new HashSet<String>();
		imgs.add("fooimg1.jpg");
		imgs.add("fooimg2.jpg");
		imgs.add("fooimg3.jpg");
		imgs.add(null);
		itemValueType.setImagesset(imgs);
		
		
		
		List<String> imgd=new ArrayList<String>();
		imgd.add("fooimg1.jpg");
		imgd.add("fooimg1.jpg");
		imgd.add("fooimg3.jpg");
		itemValueType.setImagesidbag(imgd);
		itemValueType.setImagesbag(imgd);
		itemValueType.setImageslist(imgd);
		
		*/
		
		
		Map<String,String> imge=new HashMap<String,String>();
		imge.put("foo 1","fooimg1.jpg");
		imge.put("foo 2","fooimg2.jpg");
		imge.put("foo 3","fooimg3.jpg");
		//itemValueType.setImagesmap(imge);
		
		
		Map<String,Image> imageComponentMap=new HashMap<String,Image>();
		Image i1=new Image("name1","fname1",1,1);
		Image i2=new Image("name2","fname2",2,2);
		imageComponentMap.put("wei", i1);
		imageComponentMap.put("wei2", i2);
		itemValueType.setImageComponentMap(imageComponentMap);
		
		s.save(itemValueType);
		tx.commit();
		s.close();
		
		
		
		Session s1=HibernateUtil.getSessionFactory().openSession();
		Transaction tx1=s1.beginTransaction();
		
		ItemValueType loaded=(ItemValueType)s1.load(ItemValueType.class, 1L);
		out("########"+loaded.getImagesmap().size()+" "+loaded.getImagesmap());
		out("########"+loaded.getImageComponentMap().size()+" "+loaded.getImageComponentMap());
		tx1.commit();
		s1.close();
		
		
		
		//HibernateUtil.stat();
		HibernateUtil.shutdown();
	}
	
	public static void getParent(Class clazz)
	{
		Class parent=clazz.getSuperclass();
	  if(parent !=null)
	  {
			System.out.println("###"+parent.getName());
			getParent(parent);
		}
	}
	
	static void out(Object obj)
	{
		System.out.println(obj);
	}
}
